GBML manual / Text

draw_text

Draws text in world space (scrolls with the camera) - e.g. a floating damage number over an enemy. Inside a Draw GUI event it is fixed to the screen instead (a HUD), and (x, y) counts from the screen’s top-left pixel.

Works differently on Game Boy - Text in a strip of the screen is drawn with the window; short text, text in the room and text at a place the game works out as it runs are made of sprites in the font's own shades, sharing the 40 sprites on the screen (10 a line).

Works differently on Game Boy Color - Text on the Game Boy Color goes in strips of the screen, or in sprites when short and centred; text in the room or at a place worked out while playing is always sprites. A new line starts the next 8-pixel row, except in words built while playing.

On other consoles this differs: see Side by side and How the consoles differ.

Syntax

draw_text(x, y, text)

Arguments

NameType
xreal
yreal
textstring

Returns

Nothing.

Description

Draws text in world space - it scrolls with the room, the same shared camera default drawing uses - the right choice for anything the text is about a specific place or instance: a floating damage number over whatever just got hit, a name tag above a character, a label pinned to a switch. Use font_set/text_align beforehand to choose how it looks; both are ambient settings that apply to every draw_text call from then on, not arguments to this call itself.

(x, y) is a place in the room, counted from the room's top-left corner. text_align decides which part of the text sits on that spot.

In a Draw GUI event the same call draws on the screen instead. Nothing about the call changes - only the event it is in. There, (x, y) counts from the top-left pixel of the screen ((0, 0) is that pixel, and the screen is 240 pixels wide and 160 tall), the text never scrolls with the camera, and it is always in front of the whole world, even a shrouded room's own shroud. That is what a score, a timer or any other on-screen readout uses: draw_text(4, 4, "SCORE 0") in a Draw GUI event is 4 pixels in from the left and 4 down, and it stays there when the camera moves. This holds for a script too: a script that draws is world text when a Draw event calls it, and screen text when a Draw GUI event does. To put text on the screen from some other event, use draw_text_anchored.

Text works with no setup at all: call this without ever calling font_set and it still draws, using the project's default font, font_default (fixed-width 8x8, printable ASCII). A build adds that font to the project as a real font asset, so you can open and change it in the Paint tab. font_set is how you switch to another font - it always overrides whatever was active before, the default included.

A \n in the string starts a new line: the next line begins at the same x, one line of the font lower, and each line is aligned by itself. draw_text(8, 8, "LIFE\nMANA") draws two lines. Drawing text has the details.

Example

draw_text(x, y - 16, "OW!");

A floating hit marker, drawn a fixed 16 pixels above this instance's own position every frame it is called - pair with a short-lived instance or an alarm to make it disappear again.

A real capture - the text OW! floating centered above the arrow, in world spaceA real capture - the text OW! floating centered above the arrow, in world space
A real capture - the text OW! floating centered above the arrow, in world space

On the GBA

Uses the current font_set()/text_align() - ambient state, like the GBA module’s own sprite_text_generator. Cached per call site, same as draw_sprite. Works with no setup: until font_set() is ever called, this draws with the engine’s own built-in fallback font, so calling this is never a silent no-op - call font_set() any time to switch to a font you declared yourself.

See also: draw_text_anchoreddraw_guifont_set